package com.wandong.cinema.entity;

import com.wandong.cinema.service.MovieService;
import com.wandong.cinema.service.ShowService;
import com.wandong.cinema.service.TicketService;
import com.wandong.cinema.service.impl.MovieServiceImpl;
import com.wandong.cinema.service.impl.ShowServiceImpl;
import com.wandong.cinema.service.impl.TicketServiceImpl;
import com.wandong.cinema.util.InputUtil;

import java.util.Date;

public class Manager extends User {
    private MovieService movieService = new MovieServiceImpl();
    private ShowService showService = new ShowServiceImpl();
    private TicketService ticketService = new TicketServiceImpl(showService);

    public Manager(String userId, String username, String password, Date registerTime, String userType, String phone) {
        super(userId, username, password, registerTime, userType, phone);
    }

    @Override
    public void showMenu() {
        while (true) {
            System.out.println("\n=== 经理菜单 ===");
            System.out.println("1. 影片管理");
            System.out.println("2. 排片管理");
            System.out.println("3. 销售统计");
            System.out.println("4. 修改个人信息");
            System.out.println("5. 退出登录");
            System.out.print("请选择操作: ");
            
            int choice = InputUtil.inputInteger();
            switch (choice) {
                case 1:
                    manageMovies();
                    break;
                case 2:
                    manageShows();
                    break;
                case 3:
                    salesStatistics();
                    break;
                case 4:
                    updatePersonalInfo();
                    break;
                case 5:
                    System.out.println("退出登录成功");
                    return;
                default:
                    System.out.println("无效选择，请重新输入");
            }
        }
    }

    private void manageMovies() {
        while (true) {
            System.out.println("\n=== 影片管理 ===");
            System.out.println("1. 添加影片");
            System.out.println("2. 删除影片");
            System.out.println("3. 修改影片");
            System.out.println("4. 查询影片");
            System.out.println("5. 返回上一级");
            System.out.print("请选择操作: ");
            
            int choice = InputUtil.inputInteger();
            switch (choice) {
                case 1:
                    movieService.addMovie();
                    break;
                case 2:
                    movieService.deleteMovie();
                    break;
                case 3:
                    movieService.updateMovie();
                    break;
                case 4:
                    movieService.queryMovies();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("无效选择，请重新输入");
            }
        }
    }

    private void manageShows() {
        while (true) {
            System.out.println("\n=== 排片管理 ===");
            System.out.println("1. 添加场次");
            System.out.println("2. 删除场次");
            System.out.println("3. 修改场次");
            System.out.println("4. 查询场次");
            System.out.println("5. 自动排片");
            System.out.println("6. 返回上一级");
            System.out.print("请选择操作: ");
            
            int choice = InputUtil.inputInteger();
            switch (choice) {
                case 1:
                    showService.addShow();
                    break;
                case 2:
                    showService.deleteShow();
                    break;
                case 3:
                    showService.updateShow();
                    break;
                case 4:
                    showService.queryShows();
                    break;
                case 5:
                    showService.autoArrangeShows();
                    break;
                case 6:
                    return;
                default:
                    System.out.println("无效选择，请重新输入");
            }
        }
    }

    private void salesStatistics() {
        System.out.println("\n=== 销售统计 ===");
        System.out.println("1. 按日统计");
        System.out.println("2. 按周统计");
        System.out.println("3. 按月统计");
        System.out.println("4. 返回上一级");
        System.out.print("请选择操作: ");
        
        int choice = InputUtil.inputInteger();
        switch (choice) {
            case 1:
                ticketService.statisticsByDay();
                break;
            case 2:
                ticketService.statisticsByWeek();
                break;
            case 3:
                ticketService.statisticsByMonth();
                break;
            case 4:
                return;
            default:
                System.out.println("无效选择，请重新输入");
        }
    }

    private void updatePersonalInfo() {
        System.out.println("\n=== 修改个人信息 ===");
        System.out.print("请输入新密码: ");
        String newPassword = InputUtil.inputString();
        System.out.print("请输入新手机号: ");
        String newPhone = InputUtil.inputString();
        
        setPassword(newPassword);
        setPhone(newPhone);
        System.out.println("个人信息修改成功");
    }
}
